<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenSSL::ASN1::Primitive - openssl: Ruby Standard Library Documentation</title>


<script src="../../js/navigation.js" defer></script>
<script src="../../js/search.js" defer></script>
<script src="../../js/search_index.js" defer></script>
<script src="../../js/searcher.js" defer></script>
<script src="../../js/darkfish.js" defer></script>

<script src="../../js/jquery-3.2.0.min.js"></script>

<script src="../../js/vue.min.js"></script>
<script src="../../js/js.cookie.min.js"></script>

<link href="../../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../../css/rdoc.css" rel="stylesheet">
<link href="../../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../../";
  var index_rel_prefix = "../../";
  var darkModeCsseHref = "../../css/rdoc-dm.css"
  var defaultModeCssHref = "../../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../../table_of_contents.html#pages">Pages</a>
    <a href="../../table_of_contents.html#classes">Classes</a>
    <a href="../../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Primitive+sub-classes+and+their+mapping+to+Ruby+classes">Primitive sub-classes and their mapping to Ruby classes</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3ABitString">OpenSSL::ASN1::BitString</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Additional+attributes">Additional attributes</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3AObjectId">OpenSSL::ASN1::ObjectId</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Additional+attributes">Additional attributes</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Examples">Examples</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Creating+EndOfContent">Creating EndOfContent</a>
    <li><a href="#class-OpenSSL::ASN1::Primitive-label-Creating+any+other+Primitive">Creating any other Primitive</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="ASN1Data.html">OpenSSL::ASN1::ASN1Data</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-to_der">#to_der</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenSSL::ASN1::Primitive">
    <h1 id="class-OpenSSL::ASN1::Primitive" class="class">
      class OpenSSL::ASN1::Primitive
    </h1>

    <section class="description">
    
<p>The parent class for all primitive encodings. Attributes are the same as for <a href="ASN1Data.html"><code>ASN1Data</code></a>, with the addition of <em>tagging</em>. <a href="Primitive.html"><code>Primitive</code></a> values can never be encoded with indefinite length form, thus it is not possible to set the <em>indefinite_length</em> attribute for <a href="Primitive.html"><code>Primitive</code></a> and its sub-classes.</p>

<h2 id="class-OpenSSL::ASN1::Primitive-label-Primitive+sub-classes+and+their+mapping+to+Ruby+classes"><a href="Primitive.html"><code>Primitive</code></a> sub-classes and their mapping to Ruby classes<span><a href="#class-OpenSSL::ASN1::Primitive-label-Primitive+sub-classes+and+their+mapping+to+Ruby+classes">&para;</a> <a href="#top">&uarr;</a></span></h2>
<ul><li>
<p>OpenSSL::ASN1::EndOfContent    &lt;=&gt; <em>value</em> is always <code>nil</code></p>
</li><li>
<p>OpenSSL::ASN1::Boolean         &lt;=&gt; <em>value</em> is <code>true</code> or <code>false</code></p>
</li><li>
<p><a href="../../Integer.html"><code>OpenSSL::ASN1::Integer</code></a>         &lt;=&gt; <em>value</em> is an <a href="../BN.html"><code>OpenSSL::BN</code></a></p>
</li><li>
<p>OpenSSL::ASN1::BitString       &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::OctetString     &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::Null            &lt;=&gt; <em>value</em> is always <code>nil</code></p>
</li><li>
<p>OpenSSL::ASN1::Object          &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::Enumerated      &lt;=&gt; <em>value</em> is an <a href="../BN.html"><code>OpenSSL::BN</code></a></p>
</li><li>
<p>OpenSSL::ASN1::UTF8String      &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::NumericString   &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::PrintableString &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::T61String       &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::VideotexString  &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::IA5String       &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::UTCTime         &lt;=&gt; <em>value</em> is a Time</p>
</li><li>
<p>OpenSSL::ASN1::GeneralizedTime &lt;=&gt; <em>value</em> is a Time</p>
</li><li>
<p>OpenSSL::ASN1::GraphicString   &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::ISO64String     &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::GeneralString   &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::UniversalString &lt;=&gt; <em>value</em> is a String</p>
</li><li>
<p>OpenSSL::ASN1::BMPString       &lt;=&gt; <em>value</em> is a String</p>
</li></ul>

<h2 id="class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3ABitString">OpenSSL::ASN1::BitString<span><a href="#class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3ABitString">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="class-OpenSSL::ASN1::Primitive-label-Additional+attributes">Additional attributes<span><a href="#class-OpenSSL::ASN1::Primitive-label-Additional+attributes">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p><em>unused_bits</em>: if the underlying BIT STRING’s length is a multiple of 8 then <em>unused_bits</em> is 0. Otherwise <em>unused_bits</em> indicates the number of bits that are to be ignored in the final octet of the BitString’s <em>value</em>.</p>

<h2 id="class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3AObjectId"><a href="ObjectId.html"><code>OpenSSL::ASN1::ObjectId</code></a><span><a href="#class-OpenSSL::ASN1::Primitive-label-OpenSSL-3A-3AASN1-3A-3AObjectId">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>NOTE: While <a href="Primitive.html#method-c-new"><code>OpenSSL::ASN1::ObjectId.new</code></a> will allocate a new <a href="ObjectId.html"><code>ObjectId</code></a>, it is not typically allocated this way, but rather that are received from parsed <a href="../ASN1.html"><code>ASN1</code></a> encodings.</p>

<h3 id="class-OpenSSL::ASN1::Primitive-label-Additional+attributes">Additional attributes<span><a href="#class-OpenSSL::ASN1::Primitive-label-Additional+attributes">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><em>sn</em>: the short name as defined in &lt;openssl/objects.h&gt;.</p>
</li><li>
<p><em>ln</em>: the long name as defined in &lt;openssl/objects.h&gt;.</p>
</li><li>
<p><em>oid</em>: the object identifier as a String, e.g. “1.2.3.4.5”</p>
</li><li>
<p><em>short_name</em>: alias for <em>sn</em>.</p>
</li><li>
<p><em>long_name</em>: alias for <em>ln</em>.</p>
</li></ul>

<h2 id="class-OpenSSL::ASN1::Primitive-label-Examples">Examples<span><a href="#class-OpenSSL::ASN1::Primitive-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>With the Exception of OpenSSL::ASN1::EndOfContent, each <a href="Primitive.html"><code>Primitive</code></a> class constructor takes at least one parameter, the <em>value</em>.</p>

<h3 id="class-OpenSSL::ASN1::Primitive-label-Creating+EndOfContent">Creating EndOfContent<span><a href="#class-OpenSSL::ASN1::Primitive-label-Creating+EndOfContent">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">eoc</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span><span class="ruby-operator">::</span><span class="ruby-constant">EndOfContent</span>.<span class="ruby-identifier">new</span>
</pre>

<h3 id="class-OpenSSL::ASN1::Primitive-label-Creating+any+other+Primitive">Creating any other <a href="Primitive.html"><code>Primitive</code></a><span><a href="#class-OpenSSL::ASN1::Primitive-label-Creating+any+other+Primitive">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre>prim = &lt;class&gt;.new(value) # &lt;class&gt; being one of the sub-classes except EndOfContent
prim_zero_tagged_implicit = &lt;class&gt;.new(value, 0, :IMPLICIT)
prim_zero_tagged_explicit = &lt;class&gt;.new(value, 0, :EXPLICIT)</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">



        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-tagging" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">tagging</span><span
                class="attribute-access-type">[RW]</span>
            </div>

            <div class="method-description">
              <p>May be used as a hint for encoding a value either implicitly or explicitly by setting it either to <code>:IMPLICIT</code> or to <code>:EXPLICIT</code>. <em>tagging</em> is not set when a ASN.1 structure is parsed using <a href="../ASN1.html#method-c-decode"><code>OpenSSL::ASN1.decode</code></a>.</p>
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          OpenSSL::ASN1::Primitive.new(value [, tag, tagging, tag_class ]) &rarr; Primitive
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><em>value</em>: is mandatory.</p>

<p><em>tag</em>: optional, may be specified for tagged values. If no <em>tag</em> is specified, the UNIVERSAL tag corresponding to the <a href="Primitive.html"><code>Primitive</code></a> sub-class is used by default.</p>

<p><em>tagging</em>: may be used as an encoding hint to encode a value either explicitly or implicitly, see <a href="../ASN1.html"><code>ASN1</code></a> for possible values.</p>

<p><em>tag_class</em>: if <em>tag</em> and <em>tagging</em> are <code>nil</code> then this is set to <code>:UNIVERSAL</code> by default. If either <em>tag</em> or <em>tagging</em> are set then <code>:CONTEXT_SPECIFIC</code> is used as the default. For possible values please cf. <a href="../ASN1.html"><code>ASN1</code></a>.</p>

<h2 id="method-c-new-label-Example">Example<span><a href="#method-c-new-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">int</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span><span class="ruby-operator">::</span><span class="ruby-constant">Integer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">42</span>)
<span class="ruby-identifier">zero_tagged_int</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span><span class="ruby-operator">::</span><span class="ruby-constant">Integer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">42</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:IMPLICIT</span>)
<span class="ruby-identifier">private_explicit_zero_tagged_int</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">ASN1</span><span class="ruby-operator">::</span><span class="ruby-constant">Integer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">42</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:EXPLICIT</span>, <span class="ruby-value">:PRIVATE</span>)
</pre>

                              <div class="method-source-code" id="new-source">
            <pre>static VALUE
ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE value, tag, tagging, tag_class;
    int default_tag;

    rb_scan_args(argc, argv, &quot;13&quot;, &amp;value, &amp;tag, &amp;tagging, &amp;tag_class);
    default_tag = ossl_asn1_default_tag(self);

    if (default_tag == -1 || argc &gt; 1) {
        if(NIL_P(tag))
            ossl_raise(eASN1Error, &quot;must specify tag number&quot;);
        if(!NIL_P(tagging) &amp;&amp; !SYMBOL_P(tagging))
            ossl_raise(eASN1Error, &quot;invalid tagging method&quot;);
        if(NIL_P(tag_class)) {
            if (NIL_P(tagging))
                tag_class = sym_UNIVERSAL;
            else
                tag_class = sym_CONTEXT_SPECIFIC;
        }
        if(!SYMBOL_P(tag_class))
            ossl_raise(eASN1Error, &quot;invalid tag class&quot;);
    }
    else{
        tag = INT2NUM(default_tag);
        tagging = Qnil;
        tag_class = sym_UNIVERSAL;
    }
    ossl_asn1_set_tag(self, tag);
    ossl_asn1_set_value(self, value);
    ossl_asn1_set_tagging(self, tagging);
    ossl_asn1_set_tag_class(self, tag_class);
    ossl_asn1_set_indefinite_length(self, Qfalse);
    if (default_tag == V_ASN1_BIT_STRING)
        rb_ivar_set(self, sivUNUSED_BITS, INT2FIX(0));

    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-to_der" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_der &rarr; DER-encoded String
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>See <a href="ASN1Data.html#method-i-to_der"><code>ASN1Data#to_der</code></a> for details.</p>

                              <div class="method-source-code" id="to_der-source">
            <pre>static VALUE
ossl_asn1prim_to_der(VALUE self)
{
    ASN1_TYPE *asn1;
    long alllen, bodylen;
    unsigned char *p0, *p1;
    int j, tag, tc, state;
    VALUE str;

    if (ossl_asn1_default_tag(self) == -1) {
        str = ossl_asn1_get_value(self);
        return to_der_internal(self, 0, 0, StringValue(str));
    }

    asn1 = ossl_asn1_get_asn1type(self);
    alllen = i2d_ASN1_TYPE(asn1, NULL);
    if (alllen &lt; 0) {
        ASN1_TYPE_free(asn1);
        ossl_raise(eASN1Error, &quot;i2d_ASN1_TYPE&quot;);
    }
    str = ossl_str_new(NULL, alllen, &amp;state);
    if (state) {
        ASN1_TYPE_free(asn1);
        rb_jump_tag(state);
    }
    p0 = p1 = (unsigned char *)RSTRING_PTR(str);
    i2d_ASN1_TYPE(asn1, &amp;p0);
    ASN1_TYPE_free(asn1);
    assert(p0 - p1 == alllen);

    /* Strip header since to_der_internal() wants only the payload */
    j = ASN1_get_object((const unsigned char **)&amp;p1, &amp;bodylen, &amp;tag, &amp;tc, alllen);
    if (j &amp; 0x80)
        ossl_raise(eASN1Error, &quot;ASN1_get_object&quot;); /* should not happen */

    return to_der_internal(self, 0, 0, rb_str_drop_bytes(str, alllen - bodylen));
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>.</p><p><a href="https://jamesbritt.bandcamp.com/">Maximum R+D</a>.  </p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

